home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / BSEND.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  6KB  |  219 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                  This module was written by Bob Hartman                  */
  13. /*                                                                          */
  14. /*                  BinkleyTerm Batch Sender State Machine                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #define NO_SEALINK_IS_TELINK 1
  49.  
  50. int BSInit (XMARGSP);
  51. int BSEnd (XMARGSP);
  52. int BSMoreFiles (XMARGSP);
  53. int BSWaitType (XMARGSP);
  54. int BSCheckFNm (XMARGSP);
  55. int BSCheckFile (XMARGSP);
  56. int BSEndSend (XMARGSP);
  57.  
  58. typedef struct
  59. {
  60.     char *state_name;
  61.     int (*state_func) (XMARGSP);
  62. } BSTATES, *BSTATEP;
  63.  
  64. BSTATES Batch_Sender[] =
  65. {
  66.     {"BSInit", BSInit},
  67.     {"BSEnd", BSEnd},
  68.     {"BS0", BSMoreFiles},
  69.     {"BS1", BSWaitType},
  70.     {"BS2", BSCheckFNm},
  71.     {"BS3", BSCheckFile},
  72.     {"BS4", BSEndSend},
  73. };
  74.  
  75. int
  76. BSInit (XMARGSP args)
  77. {
  78.     args->result = (int) args->control;
  79.     XON_DISABLE ();
  80.     return ((int) args->control);
  81. }
  82.  
  83. int
  84. BSEnd (XMARGSP args)
  85. {
  86.     args->result = (int) args->control;
  87.     return ((int) args->control);
  88. }
  89.  
  90. int
  91. BSMoreFiles (XMARGSP args)
  92. {
  93.     if (args->filename != NULL)
  94.     {
  95.         /* BS0.1 */
  96.         return (BS1);
  97.     }
  98.     else
  99.     {
  100.         /* BS0.2 */
  101.         return (BS4);
  102.     }
  103. }
  104.  
  105. int
  106. BSWaitType (XMARGSP args)
  107. {
  108.     long BS1Timer;
  109.     int in_char;
  110.  
  111.     BS1Timer = timerset (2000);
  112.     while (!timeup (BS1Timer))
  113.     {
  114.         if ((in_char = PEEKBYTE ()) >= 0)
  115.         {
  116.             switch (in_char)
  117.             {
  118.             case NAK:
  119.  
  120.                 /* State BS1.1 */
  121.                 args->result = Modem7_Send_File (args->filename);
  122.                 return (BS2);
  123.  
  124.             case WANTCRC:
  125.  
  126.                 /* State BS1.2 */
  127.                 if (!no_sealink)
  128.                 {
  129.                     args->result = SEAlink_Send_File (args->filename, NULL);
  130.                     return (BS3);
  131.                 }
  132. #ifdef NO_SEALINK_IS_TELINK
  133.                 else
  134.                 {
  135.                     args->result = Telink_Send_File (args->filename, NULL);
  136.                     return (BS3);
  137.                 }
  138. #endif
  139.                 /* Fallthrough if we aren't doing SEAlink */
  140.  
  141.             default:
  142.  
  143.                 /* State BS1.3 */
  144.                 (void) TIMED_READ (0);
  145.                 time_release ();
  146.             }
  147.         }
  148.         else
  149.         {
  150.             if (!CARRIER)
  151.                 return (CARRIER_ERR);
  152.             else
  153.                 time_release ();
  154.         }
  155.     }
  156.  
  157.     /* State BS1.4 */
  158.     return (TIME_ERR);
  159. }
  160.  
  161. int
  162. BSCheckFNm (XMARGSP args)
  163. {
  164.     if (args->result == SUCCESS)
  165.     {
  166.         /* State BS2.1 */
  167.         args->result = Telink_Send_File (args->filename, NULL);
  168.         return (BS3);
  169.     }
  170.     else
  171.     {
  172.         /* State BS2.2 */
  173.         return (FNAME_ERR);
  174.     }
  175. }
  176.  
  177. int
  178. BSCheckFile (XMARGSP args)
  179. {
  180.     return (args->result);
  181. }
  182.  
  183. int
  184. BSEndSend (XMARGSP args)
  185. {
  186.     long BS4Timer;
  187.  
  188.     BS4Timer = timerset (1000);
  189.     while (!timeup (BS4Timer))
  190.     {
  191.         switch (TIMED_READ (1))
  192.         {
  193.         case NAK:
  194.         case WANTCRC:
  195.  
  196.             SENDBYTE (EOT);
  197.             args->result = SUCCESS;
  198.             return (SUCCESS);
  199.         }
  200.     }
  201.  
  202.     /* State BS4.2 */
  203.     SENDBYTE (EOT);
  204.     args->result = SUCCESS;
  205.     return (SUCCESS);
  206. }
  207.  
  208. int
  209. Batch_Send (char *filename)
  210. {
  211.     XMARGS batch;
  212.     int res;
  213.  
  214.     batch.result = 0;
  215.     batch.filename = filename;
  216.     res = state_machine ((STATEP) Batch_Sender, &batch, 2);
  217.     return (res);
  218. }
  219.